package com.ruoyi.result.longitudinalProjects.mapper;

import java.util.List;
import java.util.Map;

import com.ruoyi.result.longitudinalProjects.domain.ResultLongitudinalProjects;
import com.ruoyi.result.longitudinalProjects.domain.dto.ResultLongitudinalProjectsDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 纵向课题Mapper接口
 *
 * @author ruoyi
 * @date 2025-01-22
 */
@Mapper
public interface ResultLongitudinalProjectsMapper
{


    /**
     * 查询纵向课题
     *
     * @param id 纵向课题主键
     * @return 纵向课题
     */
    public ResultLongitudinalProjects selectResultLongitudinalProjectsById(Long id);

    /**
     * 查询纵向课题列表
     *
     * @param resultLongitudinalProjects 纵向课题
     * @return 纵向课题集合
     */
    public List<ResultLongitudinalProjects> selectResultLongitudinalProjectsList(ResultLongitudinalProjectsDTO resultLongitudinalProjects);

    /**
     * 新增纵向课题
     *
     * @param resultLongitudinalProjects 纵向课题
     * @return 结果
     */
    public int insertResultLongitudinalProjects(ResultLongitudinalProjects resultLongitudinalProjects);

    /**
     * 修改纵向课题
     *
     * @param resultLongitudinalProjects 纵向课题
     * @return 结果
     */
    public int updateResultLongitudinalProjects(ResultLongitudinalProjects resultLongitudinalProjects);

    /**
     * 删除纵向课题
     *
     * @param id 纵向课题主键
     * @return 结果
     */
    public int deleteResultLongitudinalProjectsById(Long id);

    /**
     * 批量删除纵向课题
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteResultLongitudinalProjectsByIds(Long[] ids);

    List<ResultLongitudinalProjects> selectResultLongitudinalProjectsByIds(Long[] ids);

    ResultLongitudinalProjects selectLongitudinalById(Long id);

    @Select("SELECT COUNT(*) FROM result_longitudinal_projects WHERE is_deleted = 0")
    long selectCount();

    @Select("SELECT YEAR(start_time) as year, COUNT(*) as count FROM result_longitudinal_projects " +
            "WHERE is_deleted = 0 " +
            "GROUP BY YEAR(start_time) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYear();

    @Select("SELECT YEAR(start_time) as year, COUNT(*) as count FROM result_longitudinal_projects " +
            "WHERE is_deleted = 0 AND user_id = #{userId} " +
            "GROUP BY YEAR(start_time) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYearAndUserId(@Param("userId") Long userId);

    List<ResultLongitudinalProjects> selectResultLongitudinalProjectsListByDept(ResultLongitudinalProjectsDTO dto);
}
